package com.aboat.view.panel;

import com.aboat.action.AddMinusRegularListener;
import com.aboat.action.DelMinusRegularListener;
import com.aboat.view.WindowFrame;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;

/**
 * 正则表达式添加面板
 *
 * @author aboat
 * @email clear_windy@yeah.net
 * @create 2017-04-09 12:58
 */
public class MinusRegularPanel extends JPanel {
    public MinusRegularPanel(){
        setPreferredSize(new Dimension(320,220));
        setLayout(new FlowLayout(FlowLayout.LEFT));

        this.setBorder(BorderFactory.createLineBorder(Color.gray,0));
        JLabel minusRegularLabel = new JLabel("禁止正则:");
        JTextField minusRegularField = new JTextField("",27);
        JButton addMinusRegularButton = new JButton("+");
        JButton delMinusRegularButton = new JButton("-");

        this.add(minusRegularLabel);
        this.add(minusRegularField);
        this.add(addMinusRegularButton);
        this.add(delMinusRegularButton);

        String[] columnNames = {"禁止正则列表"};   //列名
        String[][] tableVales={}; //数据
        WindowFrame.minusRegularTableModel = new DefaultTableModel(tableVales,columnNames);
        JTable table = new JTable(WindowFrame.minusRegularTableModel );
        addMinusRegularButton.addActionListener(new AddMinusRegularListener(WindowFrame.minusRegularTableModel,minusRegularField));
        delMinusRegularButton.addActionListener(new DelMinusRegularListener(WindowFrame.minusRegularTableModel,table));
        table.setPreferredScrollableViewportSize(new Dimension(285, 120));
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane scrollpane = new JScrollPane(table);
        this.add(scrollpane);
    }
}
